﻿using System;
using System.Collections.Generic;

namespace Grimgine.Core
{
    /// <summary>
    /// 
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public interface IListener<T>
    {
        /// <summary>
        /// Adds a listener.
        /// </summary>
        /// <param name="listener">The listener to add</param>
        void AddListener(T listener);

        /// <summary>
        /// Removes a listener.
        /// </summary>
        /// <param name="listener">The listener to remove</param>
        void RemoveListener(T listener);

        /// <summary>
        /// Notify all the subjects.
        /// </summary>
        void Notify();
    }

    /// <summary>
    /// 
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public abstract class Listener<T>
    {
        /// <summary>
        /// A list to hold the listeners associated with the class.
        /// Each item in the list will get notified.
        /// </summary>
        protected List<T> listenerList;

        /// <summary>
        /// Adds a listener.
        /// </summary>
        /// <param name="listener">The listener to add</param>
        public void AddListener(T listener)
        {
            listenerList.Add(listener);
        }

        /// <summary>
        /// Removes a listener.
        /// </summary>
        /// <param name="listener">The listener to remove</param>
        public void RemoveListener(T listener)
        {
            listenerList.Remove(listener);
        }

        /// <summary>
        /// Notifies all the items in the list.
        /// </summary>
        public abstract void Notify();
    }
}
